//
//  AppDelegate.m
//  DHKuaiYi
//
//  Created by xiaohuihui on 2016/11/12.
//  Copyright © 2016年 30-陈辉华. All rights reserved.
//

#import "AppDelegate.h"
#import <MMDrawerController.h>
#import <UIViewController+MMDrawerController.h>
#import "DHTabBarViewController.h"
#import "DHLeftBarVC.h"
#import "ZFBNewFeatureView.h"

@interface AppDelegate ()

//侧滑控制器
@property (nonatomic, strong) MMDrawerController *drawerController;

//左边控制器
@property (nonatomic, strong) UIViewController *leftViewController;

@end

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    //创建main控制器
    DHTabBarViewController *centerTabBarViewController = [[DHTabBarViewController alloc] init];
    
    //创建leftBarViewController
    DHLeftBarVC *leftViewController = [[DHLeftBarVC alloc] init];
    
    //记录属性
    self.leftViewController = leftViewController;
    
    //建立侧滑控制器
    MMDrawerController *drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerTabBarViewController leftDrawerViewController:leftViewController];
    
    //记录属性
    self.drawerController = drawerController;
    
    //取出是否第一次启动app的值
    NSInteger count = [[NSUserDefaults standardUserDefaults] integerForKey:AppFirstTime];

    //如果count为0说明是第一次启动
    if (!count) {
        //创建新特性的scorllview
        ZFBNewFeatureView *newFeatureView = [[ZFBNewFeatureView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        [drawerController.view addSubview:newFeatureView];
        
        newFeatureView.imgs = [self getNewFeatureImgs];
    }
    
    _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _window.rootViewController = drawerController;
    [_window makeKeyAndVisible];
    
    return YES;
}

#pragma mark - 提供图片数组的方法
- (NSArray *)getNewFeatureImgs {
    
    int count = 4;
    
    //根据图片的数量来循环创建图片对象
    //并且添加到数组中
    NSMutableArray *imgsM = [NSMutableArray array];
    for (int i = 0; i < count; i++) {
        NSString *imgName = [@"common_h" stringByAppendingFormat:@"%d",i+1];
        UIImage *img = [UIImage imageNamed:imgName];
        [imgsM addObject:img];
    }
    
    /*---------- 存一个数据来判断是否第一次启动app ----------*/
    [[NSUserDefaults standardUserDefaults] setInteger:count forKey:AppFirstTime];
    
    return imgsM;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
